import 'package:flutter/material.dart';

class GoodsDetail extends StatefulWidget {
  const GoodsDetail({Key? key}) : super(key: key);

  @override
  State<GoodsDetail> createState() => _GoodsDetailState();
}

class _GoodsDetailState extends State<GoodsDetail> {
  bool isCollect = true;
  String text = "收藏";
  @override
  Widget build(BuildContext context) {
    Map<String, dynamic>? detail =
        ModalRoute.of(context)?.settings.arguments as Map<String, dynamic>?;
    // print(detail);
    return Scaffold(
      appBar: AppBar(
        title: const Text("商品详情"),
        backgroundColor: Colors.pink[200],
        // 阴影
        elevation: 2.0,
        // 文字居中
        centerTitle: true,
      ),
      body: Column(children: [
        Expanded(
          child: ListView(
            scrollDirection: Axis.vertical,
            children: [
              //图片详情
              SizedBox(
                width: double.infinity,
                height: 200,
                // 商品图片
                child: Image.asset(
                  detail!["url"],
                  fit: BoxFit.cover,
                ),
              ),
              //
              Container(
                  padding: const EdgeInsets.all(3),
                  child: Column(
                    children: [
                      const Padding(padding: EdgeInsets.all(10)),
                      Text(
                        detail["title"],
                        style: const TextStyle(
                            fontSize: 25, fontWeight: FontWeight.bold),
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ),
                      const SizedBox(
                        height: 20,
                      ),
                      Flex(
                        direction: Axis.horizontal,
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "￥" + detail["price"].toString(),
                            style: const TextStyle(
                                color: Colors.red,
                                fontSize: 28,
                                fontWeight: FontWeight.bold),
                          ),
                          ElevatedButton(
                              onPressed: () {
                                setState(() {
                                  isCollect = !isCollect;
                                });
                                if (isCollect) {
                                  setState(() {
                                    text = "收藏";
                                  });
                                print("未收藏..");
                                }else{
                                  setState(() {
                                    text = "已收藏";
                                  });
                                print("已收藏..");
                                }
                              },
                              child: Text(text)),
                        ],
                      ),
                      Text(
                        "    " + detail["desc"].toString(),
                        style: const TextStyle(
                          fontSize: 16,
                        ),
                        // maxLines: 6,
                        // overflow: TextOverflow.ellipsis,
                      ),
                    ],
                  )),
            ],
          ),
          flex: 1,
        ),
        Container(
          width: double.infinity,
          height: 40,
          padding: const EdgeInsets.fromLTRB(3, 5, 3, 2),
          child: Flex(
            direction: Axis.horizontal,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              ElevatedButton(
                  onPressed: () {
                    print("加入购物车..");
                  },
                  child: const Text("加入购物车")),
              ElevatedButton(
                  onPressed: () {
                    print("立即购买..");
                  },
                  child: const Text("立即购买")),
            ],
          ),
        )
      ]),
    );
  }
}
